const carts = [
  {
    id: 1,
    amount: 2,
    chk: false,
    product: {
      name: "玲娜贝尔",
      price: 2,
    },
  },
  {
    id: 2,
    amount: 1,
    chk: true,
    product: {
      name: "小新",
      price: 1,
    },
  },
  {
    id: 3,
    amount: 10,
    chk: true,
    product: {
      name: "小葵",
      price: 2,
    },
  },
];

// filter过滤
// reduce聚合
const sumPrice = carts
  .filter((item) => item.chk)
  .reduce((pre, cur) => pre + cur.amount * cur.product.price, 0);
console.log(sumPrice);
